package com.company.huisuo.biz.dialog

import android.app.Activity
import androidx.recyclerview.widget.GridLayoutManager
import com.company.huisuo.R
import com.company.huisuo.base.BaseCenterPopupView
import com.company.huisuo.biz.adapter.MemberRechargeAdapter
import com.company.huisuo.databinding.DialogMemberRechargeBinding
import com.lxj.xpopup.XPopup

/**
 * 会员充值
 */
class MemberRechargeDialog(activity: Activity, val dismissListener: () -> Unit) :
    BaseCenterPopupView<DialogMemberRechargeBinding>(
        activity
    ) {
    private val mScanSuccessDialog by lazy {
        XPopup.Builder(activity).asCustom(ScanSuccessDialog(activity) {
            //支付成功

        })
    }
    private val mScanPayDialog by lazy {
        XPopup.Builder(activity).asCustom(ScanPayDialog(activity) {
            //支付成功
            mScanSuccessDialog.show()
        })
    }
    private val mCustomDialog by lazy {
        XPopup.Builder(activity).asCustom(MemberRechargeCustomDialog(activity) {
            mScanPayDialog.show()
        })
    }
    private val mAdapter by lazy {
        MemberRechargeAdapter({
            //扫码
            mScanPayDialog.show()
        }, {
            //输入
            mCustomDialog.show()
        })
    }

    override val getLayoutId: Int
        get() = R.layout.dialog_member_recharge
    override val getViewBinding: DialogMemberRechargeBinding
        get() = DialogMemberRechargeBinding.bind(contentView)

    override fun initData() {
        mBinding.ivClose.setOnClickListener {
            dismiss()
        }
        mBinding.rcvList.apply {
            layoutManager = GridLayoutManager(activity, 3)
            adapter = mAdapter
        }
        val list = arrayListOf<Int>()
        list.add(100)
        list.add(300)
        list.add(500)
        list.add(1000)
        list.add(2000)
        list.add(3000)
        list.add(4000)
        list.add(5000)
        list.add(999)
        mAdapter.submitList(list)
    }

    override fun onDismiss() {
        super.onDismiss()
        dismissListener.invoke()
    }
}